package com.campusbackend.mapper;

import com.campusbackend.entity.CompetitionExperiences;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 参赛经历表 Mapper 接口
 * </p>
 *
 * @author yezi
 * @since 2025-07-24
 */
@Mapper
public interface CompetitionExperiencesMapper extends BaseMapper<CompetitionExperiences> {

    /**
     * 根据用户类型和用户ID查询参赛经历列表
     * @param userType 用户类型（1-教师，2-学生）
     * @param userId 用户ID
     * @return 参赛经历列表
     */
    @Select("SELECT * FROM competition_experiences WHERE user_type = #{userType} AND user_id = #{userId} ORDER BY start_time DESC, create_time DESC")
    List<CompetitionExperiences> selectByUserTypeAndUserId(Byte userType, Long userId);

    /**
     * 根据参赛经历ID和用户信息查询单个参赛记录（用于权限校验）
     * @param id 参赛经历ID
     * @param userType 用户类型
     * @param userId 用户ID
     * @return 参赛记录
     */
    @Select("SELECT * FROM competition_experiences WHERE id = #{id} AND user_type = #{userType} AND user_id = #{userId}")
    CompetitionExperiences selectByIdAndUser(Long id, Byte userType, Long userId);
} 